﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BattleCore.Events;
using PsyModules;

namespace Battle
{
    public class TimerFunctions
    {
        private Queue<string> _WatchDamageList = new Queue<string>();
        public Queue<string> WatchDamageList
        {
            get { return _WatchDamageList; }
            set { _WatchDamageList = value; }
        }

        private string _NextOnWDList;
        public string NextOnWDList
        {
            get { return _NextOnWDList; }
            set { _NextOnWDList = value; }
        }

        PlayerPositionEvent BotPosition = new PlayerPositionEvent();

        ShortChat msg = new ShortChat();
        // cycle bot so it can monitor all of pub
        int x, y = 0;
        ushort[] botX = new ushort[] { 331, 512, 693 };
        ushort[] botY = new ushort[] { 434, 587, 740 };
        DateTime BotPosRefreshTimestamp = DateTime.Now;
        double BotRefreshrate = 50;
        double WatchDamageDelay = 5;
        DateTime WDTimestamp = DateTime.Now;
        
        private void NextBotPosition()
        {
            // Set bot on top of start safe box
            BotPosition.MapPositionX = (ushort)(botX[x] * 16);
            BotPosition.MapPositionY = (ushort)(botY[y] * 16);

            y++;

            if (y > 2)
            { y = 0; x++; }

            if (x > 2)
                x = 0;
        }
        public Queue<EventArgs> UpdateTimer()
        {
            Queue<EventArgs> reply = new Queue<EventArgs>();

            if ((BotPosRefreshTimestamp - DateTime.Now).Duration() > TimeSpan.FromMilliseconds(BotRefreshrate))
            {
                BotPosRefreshTimestamp = DateTime.Now;
                NextBotPosition();
                reply.Enqueue(BotPosition);
            }

            if ((WDTimestamp - DateTime.Now).Duration() > TimeSpan.FromSeconds(WatchDamageDelay))
            {
                WDTimestamp = DateTime.Now;
                if (_WatchDamageList.Count > 0)
                {
                    NextOnWDList = _WatchDamageList.Dequeue();
                    reply.Enqueue(msg.pm(NextOnWDList, "*watchdamage"));
                }
            }

            return reply;
        }
    }
}
